package unit;

import junit.framework.TestCase;

import com.google.code.netcheckin.aprs.AprsPacketData;
import com.google.code.netcheckin.util.ByteUtils;

public class UAprsPacketData extends TestCase {

	protected TestAprsPacketData packetData;

	public UAprsPacketData(String name) {
		super(name);
	}

	public void setUp() {
		packetData = new TestAprsPacketData();
	}

	public void tearDown() {
		packetData = null;
	}

	public void testAAAddPacketBytes() {
		packetData.setSourceAddress(new byte[] { 'A' });
		packetData.setDestAddress(new byte[] { 'B' });
		packetData.setPath(new byte[] { 'C' });
		byte[] pkbytes = new byte[64];
		byte[] correct = "A>B:C".getBytes();
		int offset = packetData.testAddPacketBytes(pkbytes, 25);
		assertEquals("1 wrong offset", (25 + correct.length), offset);
		assertTrue("1 no data", ByteUtils.areValuesAt(correct, pkbytes, 25));
		offset = packetData.testAddPacketBytes(pkbytes, 0);
		assertEquals("2 wrong offset", correct.length, offset);
		assertTrue("2 no data", ByteUtils.areValuesAt(correct, pkbytes, 0));
	}

		/** Make non-abstract and provide access to protected method for testing. */
	protected class TestAprsPacketData extends AprsPacketData {
		public TestAprsPacketData() {
		}
		public byte[] toPacket() {
			return null;
		}
		public int testAddPacketBytes(byte[] buf, int offset) {
			return addPacketBytes(buf, offset);
		}
	}

}
